In [1]:
from pyrise import products
from pyrise.products import PRODUCT_ID
from pyrise.downloads import download_browse_product
In [5]:
obsid = 'PSP_003092_0985_RED'
In [8]:
from urllib.request import urlretrieve
In [10]:
"""Download a browse product from HiRISE website.
By default, store it in current path.
Parameters
----------
obsid : str
HiRISE observation ID
kind : {'RED','COLOR'}, optional
String indicating the kind of required browse product. Default: 'RED'
annotated : bool, optional
Switch to control if the annotated version is required. Default: True
saveroot : str, pathlib.Path, optional
Path in where the browse product is being stored. Default: '.'
overwrite : bool, optional
Boolean switch to control if an existing path should be overwritten. Default: False
"""
kind='RED'
pid = PRODUCT_ID(f"{obsid}_{kind}")
url = pid.browse_url
print("URL:", url)
savepath = 'test.jpg'
print("Downloading\n", url, '\nto\n', savepath)
try:
urlretrieve(url, str(savepath))
except HTTPError as e:
print(e)
Out[10]:
Out[10]:
In [11]:
!open test.jpg
In [68]:
download_browse_product(obsid, annotated=False)
Out[68]:
In [70]:
!open {_}
In [71]:
def download_browse_list(obsids, **kwargs):
"""Download browse products for a list of obsids.
Parameters
----------
obsids : iterable
Container with HiRISE observation ID strings
Example
-------
download_browse_list(['PSP_003092_0985', 'ESP_020146_0950'])
"""
for obsid in obsids:
download_browse_product(obsid, **kwargs)
In [76]:
download_browse_list(['PSP_003092_0985', 'ESP_020146_0950'], kind='COLOR')
In [169]:
from pptx import Presentation
from scipy.misc import imread
def create_browse_presentation(obsids, **kwargs):
prs = Presentation()
pic_left = int(prs.slide_width * 0.0)
pic_top = int(prs.slide_height * 0.0)
blank_slide_layout = prs.slide_layouts[6]
for obsid in obsids[0:]:
imgpath = str(download_browse_product(obsid, **kwargs))
slide = prs.slides.add_slide(blank_slide_layout)
img = imread(imgpath)
ratio = img.shape[0] / img.shape[1]
if ratio < 1:
pic_width = int(prs.slide_width)
pic_height = int(pic_width * img.shape[0] / img.shape[1])
else:
pic_height = int(prs.slide_height)
pic_width = int(pic_height / ratio)
pic = slide.shapes.add_picture(imgpath, pic_left, pic_top, pic_width, pic_height)
prs.save('obsid_browse_images.pptx')
In [170]:
obsids = ['PSP_003092_0985', 'ESP_020146_0950']
In [171]:
create_browse_presentation(obsids)
In [ ]: